Grid2vectorInteger Subroutine

public subroutine Grid2vectorInteger(grid, vector)

return an array 1D of numbers different than nodata in a grid_integer

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: grid
integer(kind=short), intent(out), ALLOCATABLE :: vector(:)

Variables

Type Visibility Attributes Name Initial
integer(kind=short), public :: count
integer(kind=short), public :: i
integer(kind=short), public :: istat
integer(kind=short), public :: j

Source Code

SUBROUTINE Grid2vectorInteger &
!
(grid, vector) 
    

IMPLICIT NONE

!Arguments with intent in
TYPE (grid_integer), INTENT(IN) :: grid

!Arguments with intent out
INTEGER (KIND = short), INTENT (OUT), ALLOCATABLE :: vector (:)

!local declarations:
INTEGER (KIND = short) :: i, j, count, istat

!---------------------end of declarations--------------------------------------

!count number of actual values in grid, skip nodata
count = 0
DO i = 1, grid % idim
    DO j = 1, grid % jdim
        IF (grid % mat (i,j) /= grid % nodata) THEN
            count = count + 1
        END IF
    END DO
END DO

!allocate vector
ALLOCATE (vector (count), STAT = istat) 

!fill in vector
count = 0
DO i = 1, grid % idim
    DO j = 1, grid % jdim
        IF (grid % mat (i,j) /= grid % nodata) THEN
            count = count + 1
            vector (count) = grid % mat (i,j)
        END IF
    END DO
END DO

RETURN
END SUBROUTINE Grid2vectorInteger